package com.sx.wechat.config;

import com.alibaba.fastjson.JSON;
import com.sx.core.utils.AesUtil;
import com.sx.core.vo.EncryptResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Pointcut;

/**
 * Created by lihao on 2018/1/15.
 */
//@Configuration
//@Aspect
public class EncrytoAdvice {
    String key= "B9E3D6DDCAA2BEE6D6C7C4DCBFC6BCBC";
    String iv= "0123456789123456";

    Log log= LogFactory.getLog(getClass());
    @Pointcut("execution(* com.sx.wechat.controller.ApiController.api(..))")
    public void aes() {

    }
    @Around("aes()")
    public Object doFindByIdChe(ProceedingJoinPoint proceedingJoinPoint){
        try {
            Object obj = proceedingJoinPoint.proceed();
            EncryptResponse response=new EncryptResponse(AesUtil.Encrypt(JSON.toJSONString(obj),key,iv));
            return response;
        } catch (Throwable throwable) {
            log.error("加密失败",throwable);
            throw new RuntimeException("加密失败");
        }
    }

}
